package edu.mis.modules.product;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import edu.mis.model.Product;

public class ProductService {

	private static final Product dao=new Product().dao();
	
	public boolean save(Product product) {
		return product.save();
	}
	
	public boolean update(Product product) {
		return product.update();
	}
	
	public boolean delete(Product product) {
		return product.delete();
	}
	
	public boolean deleteProductById(int id) {
		return dao.deleteById(id);
	}
	
	public Product findProductById(int id) {
		return dao.findById(id);
	}
	
	public List<Product> findAll(){
		return dao.find("select * from product");
	}
	
	public List<Record> findAllProductWithType(){
		return Db.find("SELECT p.*,t.typeName FROM product p LEFT JOIN type t ON p.typeId=t.typeId");
	}
}